package com.github.xuchen93.forlaozeng.opreate_1;

import java.util.Scanner;

/**
 * @author xuchen.wang
 */
public class Subject_3 {

	public static void main(String[] args) {
		System.out.println("##计算器##");
		System.out.println("请输入任意键开始");
		Scanner scanner = new Scanner(System.in);
		while (!"exit".equalsIgnoreCase(scanner.next())){
			System.out.println("请输入第一个数");
			String firstInput = scanner.next();
			Integer first;
			try {
				first = Integer.parseInt(firstInput);
			} catch (Exception e){
				System.out.println("输入错误，不是数字类型");
				System.out.println("请输入任意键重新开始或exit退出");
				continue;
			}
			System.out.println("请输入计算符号（+,-,*,/）");
			String calc = scanner.next();
			if (calc.length() != 1 || !"+-*/".contains(calc)){
				System.out.println("输入错误，不是计算符号");
				System.out.println("请输入任意键重新开始或exit退出");
				continue;
			}
			System.out.println("请输入第二个数");
			Integer second;
			String secondInput = scanner.next();
			try {
				second = Integer.parseInt(secondInput);
			} catch (Exception e){
				System.out.println("输入错误，不是数字类型");
				System.out.println("请输入任意键重新开始或exit退出");
				continue;
			}
			if ("/".equals(calc) && second == 0){
				System.out.println("输入错误，0不能作为除数");
				System.out.println("请输入任意键重新开始或exit退出");
				continue;
			}
			int result = 0 ;
			switch (calc){
				case "+":
					result = first+second;
					break;
				case "-":
					result = first-second;
					break;
				case "*":
					result = first*second;
					break;
				case "/":
					result = first/second;
					break;
			}
			System.out.println("计算结果");
			System.out.println(first+calc+second+"="+result);
			System.out.println("请输入任意键重新开始或exit退出");
		}
	}
}
